//
//  mySearchBar.m
//  Weibo2
//
//  Created by Gate on 15/11/5.
//  Copyright © 2015年 Gate. All rights reserved.
//

#import "mySearchBar.h"

@implementation mySearchBar
+ (instancetype)searchBar{
    return [[self alloc]init];
}
- (id)initWithFrame:(CGRect)frame{
    if (self) {
        self = [super initWithFrame:frame];
        [self setBackground:[UIImage resizedImagewithName:@"searchbar_textfield_background_os7"]];
        
        UIImageView *iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"searchbar_textfield_search_icon"]];
        iconView.frame = CGRectMake(0, 0, 30, 30);
        iconView.contentMode = UIViewContentModeCenter;
        self.leftView = iconView;
        self.leftViewMode = UITextFieldViewModeAlways;
        self.font = [UIFont systemFontOfSize:13];
        self.clearButtonMode = UITextFieldViewModeAlways;
        //    searchBar.placeholder = @"搜索";
        NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
        attrs[NSForegroundColorAttributeName] = [UIColor greenColor];
        //    attrs[NSBaselineOffsetAttributeName] = [NSValue valueWithUIOffset:UIOffsetZero];
        attrs[NSFontAttributeName] = [UIFont boldSystemFontOfSize:16];
        self.attributedPlaceholder = [[NSAttributedString alloc]initWithString:@"搜索" attributes:attrs];
        //设置键盘右下角按钮的样式
        self.returnKeyType = UIReturnKeySearch;
        self.enablesReturnKeyAutomatically = YES;
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    self.leftView.frame = CGRectMake(0, 0, 30, self.frame.size.height);
}
@end
